<template>
  <div class="upstateProductMain">
    <div class="bc"></div>
    <div class="content">
      <div class="con_title">修改{{title}}<i class="el-icon-close" @click="close"></i></div>
      <div class="con_con">
        <div class="con_input">
          <span class="ci_text">{{title}}</span>
          <div class="ci_input">
            <el-input v-model="actualAmount" :placeholder="'请输入' + title"></el-input>
          </div>
        </div>
      </div>
      <footer>
        <div class="buttons">
          <el-button @click="close">取消</el-button>
          <el-button type="primary" @click="agree" style="height: 40px">确认</el-button>
        </div>
      </footer>
    </div>
  </div>
</template>

<script>
  import {mapActions} from 'vuex'
  export default {
    props:['updateProDate','upType'],
    name: "upstateProduct",
    data() {
      return {
        title:'',
        actualAmount:''
      }
    },
    mounted() {
      let self = this
      if (self.updateProDate != undefined && self.updateProDate != null && self.updateProDate != ''){
        if (self.upType == 1){ //实际产量
          self.title = '实际产量'
          self.actualAmount = self.updateProDate.actualAmount
        } else if (self.upType == 2){ //人员配置
          self.title = '人员配置'
          self.actualAmount = self.updateProDate.member_amount
        } else if (self.upType == 3){ //产线产能
          self.title = '产线产能'
          self.actualAmount = self.updateProDate.output
        } else if (self.upType == 4){ //安全库存
          self.title = '安全库存'
          self.actualAmount = self.updateProDate.value
        } else if (self.upType == 5){ //提前期(安全库存)
          self.title = '提前期'
          self.actualAmount = self.updateProDate.leadTime
        }
      }
    },
    methods: {
      ...mapActions([
        'upstate'
      ]),
      //取消
      close(){
        let self = this
        self.upstate({key:'showUpstatePro',val:false})
      },
      //确认
      agree(){
        let self = this
        if (self.upType == 1){ //实际产量
          let params={
            "actualAmount": self.actualAmount,
            "modifier": localStorage.getItem('firstName'),
            "product":self.updateProDate.product,
            "time": self.updateProDate.time2,
            "timestamps": self.updateProDate.timestamps,
          }
          self.$http.post(self.conURL + 'pm/api/scheduling/post',params).then(res => {
            this.$notify({
              title: '成功',
              message: '修改实际产量成功',
              type: 'success'
            });
            self.close()
            this.$emit('getBack',1)
          })
        } else if (self.upType == 2){ //人员配置
          for (let i = 0; i < self.updateProDate.hourList.length; i++){
            let par = {
              'id': self.updateProDate.hourList[i].id,
              'memberAmount': parseInt(self.actualAmount)
            }
            self.$http.post(self.conURL + 'pm/api/product_line',par)
          }
          this.$notify({
            title: '成功',
            message: '修改人员配置成功',
            type: 'success'
          });
          self.close()
          this.$emit('getBack',2)
        } else if (self.upType == 3){ //产线产能
          let params={
            "id": self.updateProDate.id,
            "outPut": parseInt(self.actualAmount),
          }
          self.$http.post(self.conURL + 'pm/api/product_line',params).then(res => {
            this.$notify({
              title: '成功',
              message: '修改产线产能成功',
              type: 'success'
            });
            self.close()
            this.$emit('getBack',3)
          })
        } else if (self.upType == 4){ //安全库存
          let params={
            "product": self.updateProDate.name,
            "safeStock": parseInt(self.actualAmount),
          }
          self.$http.post(self.conURL + 'pm/api/safe_stock',params).then(res => {
            this.$notify({
              title: '成功',
              message: '修改安全库存成功',
              type: 'success'
            });
            self.close()
            this.$emit('getBack',4)
          })
        } else if (self.upType == 5){ //提前期(安全库存)
          let params={
            "product": self.updateProDate.name,
            "leadTime": parseInt(self.actualAmount),
          }
          self.$http.post(self.conURL + 'pm/api/leadTime',params).then(res => {
            this.$notify({
              title: '成功',
              message: '修改提前期成功',
              type: 'success'
            });
            self.close()
            this.$emit('getBack',5)
          })
        }
      },
    }
  }
</script>

<style lang="less">
  .upstateProductMain{
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    .bc{
      width: 100%;
      height: 100%;
      z-index: 9;
      background: #000;
      opacity: .3;
      position: fixed;
      left: 0;
      top: 0;
    }
    .content{
      width: 450px;
      height: 273px;
      margin: auto;
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      background: #fff;
      z-index: 10;
      border-radius: 3px;
      border: 1px solid #e5e5e5;
      display: flex;
      flex-direction: column;
      .con_title{
        width: 100%;
        height: 50px;
        line-height: 50px;
        text-align: center;
        font-size: 16px;
        color: #999999;
        background: #fafafa;
        border-bottom: 1px solid #e5e5e5;
        position: relative;
        .el-icon-close{
          position: absolute;
          font-size: 16px;
          right: 17px;
          top: 17px;
          cursor: pointer;
        }
      }
      .con_con{
        display: flex;
        flex-direction: column;
        padding: 30px 39px;
        box-sizing: border-box;
        min-height: 160px;
        border-bottom: 1px solid #e5e5e5;
        .con_input{
          width: 100%;
          height: 40px;
          display: flex;
          flex-direction: row;
          .ci_text{
            font-size: 14px;
            color: #666666;
            line-height: 40px;
            margin-right: 28px;
          }
          .ci_input{
            width: 285px;
            height: 40px;
          }
        }
      }
      footer{
        background: #fafafa;
        width: 100%;
        height: 60px;
        display: flex;
        flex-direction: row;
        justify-content: center;
        .buttons{
          margin-top: auto;
          margin-bottom: auto;
          display: flex;
          flex-direction: row;
        }
      }
    }
  }
</style>
